<template>
  <div class="app-container">
    <ContentWrap>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="任务编号" prop="taskNo">
        <el-input
          v-model="queryParams.taskNo"
          placeholder="请输入任务编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="deviceNum">
        <el-input
          v-model="queryParams.deviceNum"
          placeholder="请输入设备编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="任务时间" >
        <el-date-picker
          v-model="dateRange"
          style="width: 410px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="渗漏状态" prop="monitorStatus">
        <el-select
          v-model="queryParams.monitorStatus"
          clearable
          placeholder="请选择渗漏状态"
        >
          <el-option
            v-for="dict in dict.type.task_detail_monitor_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['swla2:taskDetail:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="detailList"
      @selection-change="handleSelectionChange"
      border
      :height="getAvailableHeight"
    >
      <el-table-column
        label="序号"
        type="index"
        :index="calculateIndex"
        width="55"
        align="center"
      />
      <el-table-column label="检漏时间" align="center" prop="reportDay" />
      <el-table-column label="设备编号" align="center" prop="deviceNum">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.deviceNum"
            type="text"
            @click="handleFormDevice(scope.row)"
          >
            <span>{{ scope.row.deviceNum }}</span>
          </el-button>
          <label v-else>暂无编号</label>
        </template>
      </el-table-column>
      <!-- <el-table-column label="设备名称" align="center" prop="deviceName" /> -->
      <el-table-column label="任务编号" align="center" prop="taskNo" />
      <el-table-column label="任务地址" align="center" prop="taskAddress" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <!-- <el-table-column label="检漏人" align="center" prop="taskNo" /> -->
      <el-table-column
        label="文件名称"
        align="center"
        prop="fileName"
        width="240"
      />
      <el-table-column label="渗漏状态" align="center" prop="monitorStatus" >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.monitorStatus"
            type="text"
            @click="handleTaskMonitorInfo(scope.row)"
          >
         
            <dict-tag
            :options="dict.type.task_detail_monitor_status"
            :value="scope.row.monitorStatus"
              />
          </el-button>
          <label v-else>暂无数据</label>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['swla2:taskDetail:edit']"
            >详情</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改任务详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form
        ref="form"
        disabled
        :model="form"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="设备台账表id" prop="deviceLedgerId">
          <el-input
            v-model="form.deviceLedgerId"
            placeholder="请输入设备台账表id"
          />
        </el-form-item>
        <el-form-item label=" 任务管理表id" prop="taskManagementId">
          <el-input
            v-model="form.taskManagementId"
            placeholder="请输入 任务管理表id"
          />
        </el-form-item>
        <el-form-item label="任务编号" prop="taskNo">
          <el-input v-model="form.taskNo" placeholder="请输入任务编号" />
        </el-form-item>
        <el-form-item label="任务地址" prop="taskAddress">
          <el-input v-model="form.taskAddress" placeholder="请输入任务地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer"></div>
    </el-dialog>

    <!--表单配置详情-->
    <el-dialog
      :title="formTitle"
      :visible.sync="formConfOpen"
      width="50%"
      append-to-body
    >
      <div class="test-form">
        <el-form
          ref="formDevice"
          :model="formDevice"
          
          label-width="110px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="设备编号" prop="deviceNum">
                <el-input
                 readonly 
                  v-model="formDevice.deviceNum"
                  placeholder="请输入任务编号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备经度" prop="longitude">
                <el-input
                readonly
                  v-model="formDevice.longitude"
                  placeholder="请输入设备经度"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="设备纬度" prop="latitude">
                <el-input
                readonly
                  v-model="formDevice.latitude"
                  placeholder="请输入设备纬度"
                  
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="所属区域" prop="taskName">
                <el-input
                readonly
                  v-model="formDevice.taskName"
                  placeholder="请输入所属区域"
                />
              </el-form-item>
            </el-col>
          </el-row>


          <el-row>
            <el-col :span="12">
              <el-form-item label="安装时间" prop="installTime">
                <el-input
                readonly
                  v-model="formDevice.installTime"
                  placeholder="请输入安装时间"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="安装位置" prop="installPosition">
                <el-input
                readonly
                  v-model="formDevice.installPosition"
                  placeholder="请输入安装位置"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="基准噪声值" prop="noiseReference">
                <el-input
                readonly
                  v-model="formDevice.noiseReference"
                  placeholder="请输入基准噪声值"
                 
                />
              </el-form-item>
            </el-col>
          
          </el-row>
        </el-form>
      </div>
    </el-dialog>



    <!--侧漏详情-->
    <el-dialog
      :title="formTitle2"
      :visible.sync="formConfOpen2"
      width="50%"
      append-to-body
    >
      <div class="test-form">
        <el-form
          ref="formDevice2"
          :model="formDevice2"
          
          label-width="110px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="设备编号" prop="deviceNum">
                <el-input
                readonly
                  v-model="formDevice2.deviceNum"
                  placeholder="请输入设备编号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检漏日期" prop="reportDay">
                <el-input
                readonly
                  v-model="formDevice2.reportDay"
                  placeholder="请输入检漏日期"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="基准噪声值(db)" prop="noiseReference">
                <el-input
                readonly
                  v-model="formDevice2.noiseReference"
                  placeholder="请输入基准噪声值"
                 
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="db值" prop="dbValue">
                <el-input
                readonly
                  v-model="formDevice2.dbValue"
                  placeholder="请输入db值"
                />
              </el-form-item>
            </el-col>
          </el-row>


          <el-row>
            <el-col :span="12">
              <el-form-item label="音频文件名" prop="fileName">
                <!-- <el-input
                  v-model="formDevice2.fileName"
                  placeholder="请输入音频文件名"
                /> -->
                <el-link :href="`${formDevice2.wavePreUrl}`" :underline="false" target="_blank">
                  <span class="el-icon-document"> {{ formDevice2.fileName}} </span>
                  <!-- <span class="el-icon-document"> {{ formDevice2.wavePreUrl}} </span> -->
                </el-link>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="渗漏状态" prop="monitorStatus">
                <el-input
                readonly 
                  v-model="formDevice2.monitorStatus"
                  placeholder="请输入渗漏状态"
                />
              </el-form-item>
            </el-col>
          </el-row>

        
        </el-form>
      </div>
    </el-dialog>

</ContentWrap>

  </div>
</template>

<script>
import {
  getDetail,
  listDetail,
  listDetailMore,
} from "@/api/leakage/taskDetail";
import { create } from "sortablejs";

export default {
  name: "Detail",
  dicts: ["task_detail_monitor_status"],
  data() {
    return {
      baseAudioUrl: process.env.VUE_APP_BASE_API + "/common/minio/download",


      formDevice2:{},
      //任务详情-设备信息
      formConfOpen2: false,
      formTitle2: "",



      formDevice:{},
      //任务详情-设备信息
      formConfOpen: false,
      formTitle: "",

      screenHeight: null,

      // 显示搜索条件
      showSearch: true,

      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务详情表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceNum: null,
        taskNo: null,
        monitorStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deviceLedgerId: [
          { required: true, message: "设备台账表id不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    const taskNo = this.$route.query && this.$route.query.taskNo;
    //  查询流程xml
    if (taskNo) {
      this.queryParams.taskNo = taskNo;
    }
    this.$nextTick(() => { 
          this.getList();
    });
    
    this.screenHeight = document.body.clientHeight;
  },
  computed: {
    getAvailableHeight() {
      return this.screenHeight - (this.showSearch ? 240 : 195);
    },
  },

  methods: {

    handleTaskMonitorInfo(row){
      // this.$router.push({ path: '/dataview/taskDetail',query: { id: row.id }})
      this.formTitle2 = "检漏详情";
      this.formConfOpen2 = true;
      this.$nextTick(() => {
        this.formDevice2 = row;
 
      });
    },    /** 表单查看 */
    handleFormDevice(row) {
      // getForm(formId).then((res) => {
      this.formTitle = "设备详情";
      this.formConfOpen = true;
      this.$nextTick(() => {
        this.formDevice = row;
 
      });
      // });
    },

    calculateIndex(index) {
      // index 是当前页的行索引（从 0 开始）
      // 返回值为最终显示的序号
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 查询任务详情列表 */
    getList() {
      this.loading = true;
      listDetailMore(
        Object.assign(this.queryParams, {
          beginTime: this.dateRange ? this.dateRange[0] : null,
          endTime: this.dateRange ? this.dateRange[1] : null,
        })
      ).then((response) => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deviceId: null,
        taskManagementId: null,
        taskNo: null,
        taskAddress: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
     
      this.$nextTick(() => {
        this.resetForm("queryForm");
        this.dateRange = [];
        this.handleQuery();
      });
     
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加任务详情";
    // },
    /** 修改按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids;
      getDetail(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看任务详情";
      });
    },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.id != null) {
    //         updateDetail(this.form).then(response => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addDetail(this.form).then(response => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.id || this.ids;
    //   this.$modal.confirm('是否确认删除任务详情编号为"' + ids + '"的数据项？').then(function() {
    //     return delDetail(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "swla2/deviceLedger/exportMore",
        {
          ...this.queryParams,
        },
        `任务详情_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}")}.xlsx`
      );
    },
  },
};
</script>
